//
//  UIButton+Extension.swift
//  WeChat
//
//  Created by 梁迪 on 15/12/17.
//  Copyright © 2015年 梁迪. All rights reserved.
//

import UIKit

extension UIButton{


    convenience init(title: String,backImageName: String?,fontSize: CGFloat,color: UIColor,imageName:String? = nil) {
    //需要调用本类的指定构造函数  实例化自己
    self.init()
        if imageName != nil{
            
           setImage(UIImage(named: imageName!), forState: .Normal)
        }
        if backImageName != nil {
            
            setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
            
        }
        
        
    
    setTitle(title, forState: .Normal)
    titleLabel?.font = UIFont.systemFontOfSize(fontSize)
    setTitleColor(color, forState: .Normal)
    sizeToFit()
}

/**
 返回一个 有背景视图 + image 按钮的样式
 
 - parameter imageName:     按钮的图片名称
 - parameter backImageName: 按钮背景图片名称
 */
convenience init(imageName: String? = nil,backImageName: String) {
    self.init()
    
    // () 自定义样式
    if imageName != nil{
    setImage(UIImage(named: imageName!), forState: .Normal)
    setImage(UIImage(named: imageName! + "_highlighted"), forState: .Highlighted)
    }
  
    
    setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
    setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: .Highlighted)
    
    //更具背景视图 自动设置大小
    sizeToFit()
    }
}